package com.wyz.saas.app.mvvm.main

import android.os.Bundle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.atom.module.mvvm.base.AbstractViewModelFactory
import com.atom.module.mvvm.base.AbstractBaseActivity
import com.atom.module.mvvm.base.EmptyModel
import com.wyz.saas.app.BR
import com.wyz.saas.app.R
import com.wyz.saas.app.databinding.ActivityMainBinding

class MainActivity : AbstractBaseActivity<ActivityMainBinding, MainViewModel>() {

    override fun initContentView(savedInstanceState: Bundle?): Int = R.layout.activity_main

    override fun initViewModel(): MainViewModel {
        val factory = object : AbstractViewModelFactory() {
            override fun <T : ViewModel?> create(modelClass: Class<T>): T {
                if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
                    return MainViewModel(BR.mainBinding, EmptyModel()) as T
                }
                return modelClass.newInstance()
            }
        }
        return ViewModelProvider(this, factory).get(MainViewModel::class.java)
    }

}